package com.personal.Visualplan.imp;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.personal.Visualplan.entity.Tag;
import com.personal.Visualplan.repository.TagRepository;
import com.personal.Visualplan.service.TagService;
/**
 * <p>Project name:VisualPlan </p> 
 * <p>Class name:TagImp.java </p>   
 * @author "HaoZhiwei"  
 * @version 1.0 
 * @date 2020年3月3日  
 * @description  
 *
 */
@Service
public class TagImp implements TagService {
	
	@Resource
	private TagRepository tagRepository;
	
	@Override
	public Tag addTag(Tag tag) {
		// TODO Auto-generated method stub
		Tag result = tagRepository.findTagById(tag.getId());
		if (result != null) {
			return null;
		} else {
			return tagRepository.save(tag);
		}
	}

	@Override
	public boolean deletTag(int id) {
		// TODO Auto-generated method stub
		Tag result = tagRepository.findTagById(id);
		if (result != null) {
			tagRepository.deleteById(id);
			return true;
		}
		return false;
	}

	@Override
	public Tag findTagById(int id) {
		// TODO Auto-generated method stub
		return tagRepository.findTagById(id);
	}

	@Override
	public Tag findTagByName(String name) {
		// TODO Auto-generated method stub
		return tagRepository.findTagByName(name);
	}
	
	@Override
	public List<Tag> getAllTags() {
		return tagRepository.findAll();
	}
}
